package com.bing.common.config;

import cn.hutool.core.collection.CollUtil;
import com.bing.common.config.interceptor.FrontInterceptor;
import com.bing.common.properties.InterceptorProperties;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.boot.autoconfigure.condition.ConditionalOnClass;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

import java.util.List;

@Configuration
@ConditionalOnClass(InterceptorProperties.class)
public class InterceptorConfig implements WebMvcConfigurer {

    @Autowired
    private FrontInterceptor frontInterceptor;

    @Value(value = "${config.interceptor.urlPatterns:}")
    private List<String> permitUrl;

    /**
     * 自定义拦截规则
     */
    @Override
    public void addInterceptors(InterceptorRegistry registry)
    {
        if(CollUtil.isEmpty(permitUrl)){
            return;
        }
        registry.addInterceptor(frontInterceptor).addPathPatterns(permitUrl);
    }

}
